package com.chunlei.complete.client;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/5/10 23:41
 */
public class CompletableFutureClient1
{
    public static void main(String[] args) throws InterruptedException, ExecutionException
    {
        Future<String> future = calculateAsync();
        String result = future.get();
        System.out.println("result = " + result);
    }

    public static Future<String> calculateAsync() throws InterruptedException {
        // CompletableFuture<String> completableFuture = new CompletableFuture<>();
        //
        // Executors.newCachedThreadPool().submit(() -> {
        //     Thread.sleep(500);
        //     completableFuture.complete("Hello");
        //     return null;
        // });

        CompletableFuture<String> completableFuture
                = CompletableFuture.supplyAsync(() -> "Hello");

        CompletableFuture<String> future = completableFuture
                .thenApply(s -> s + " World");

        
        return completableFuture;
    }
}
